﻿using System;
using System.Collections.Generic;
using System.Linq;
using Medianamik.Globalization;
using Medianamik.UI.Web.Services;
using NUnit.Framework;

namespace Medianamik.Tests.Integration.Medianamik.UI.Web.Services
{
    [TestFixture]
    public class ResourceServiceTest
    {
        private string _myAssemblyName;
        [SetUp]
        public void Init()
        {
            _myAssemblyName = AppDomain.CurrentDomain.FriendlyName;
        }

        [Test]
        public void GetAllNewOrUpdatedResources_should_not_return_null_or_throw_any_exception_when_queried_with_today_datetime()
        {
            IEnumerable<Resource> newOrUpdatedResources = null;
            
            Service<IResourceService>.Use(resourceService =>
              {
                  
                  newOrUpdatedResources = resourceService
                      .GetAllNewOrUpdatedResources(_myAssemblyName, new[] { "fr-ca" }, DateTime.Now).ToList();

              });

            Assert.That(newOrUpdatedResources, Is.Not.Null);
        }

        [Test]
        public void GetAllNewOrUpdatedResources_should_return_empty_enumerable_when_date_requested_is_too_old()
        {
            IEnumerable<Resource> newOrUpdatedResources = null;

            Service<IResourceService>.Use(resourceService =>
            {

                newOrUpdatedResources = resourceService
                    .GetAllNewOrUpdatedResources(_myAssemblyName, new[] { "fr-ca" }, DateTime.MinValue).ToList();

            });

            Assert.That(newOrUpdatedResources, Is.Empty);
        }
        
    }
}